﻿Imports System.Data.OleDb
Public Class frmLogin
    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;Data Source=|DataDirectory|\PsychologicalStateTracker.mdb")
        Dim cmd As OleDbCommand = New OleDbCommand( _
                   "SELECT * FROM tblLogin WHERE LoginUsername = '" & _
                   txtUsername.Text & "' AND LoginPassword = '" & txtPassword.Text & "' ", con)
        con.Open()
        Dim sdr As OleDbDataReader = cmd.ExecuteReader()
        ' If the record can be queried, it means passing verification, then open another form.   
        If (sdr.Read() = True) Then
            MessageBox.Show("You have been successfully authenticated!")
            frmMain.Show()
            Me.Hide()
        Else
            MessageBox.Show("Invalid username and/or password!")
        End If
    End Sub
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Me.Close()
    End Sub

    Private Sub lblChangeLoginDetails_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblChangeLoginDetails.LinkClicked

        frmChangeLoginDetails.Show()
        Me.Hide()

    End Sub
End Class
